package J11_9.J11_8.operation;

import J11_9.J11_8.book.Book;
import J11_9.J11_8.book.BookList;

import java.util.Scanner;
import java.util.Scanner;

public class AddBook implements IOperation {

    @Override
    public void work(BookList bookList) {

        System.out.println("新增图书");
        if( bookList.getBookCount() == bookList.getMAX_BOOKCOUNT() ){
            System.out.println("书架已满");
            return;
        }
        Scanner in = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = in.nextLine();
        for (int i = 0; i < bookList.getBookCount(); i++) {
            if(bookList.getBooks(i).getName().equals(name)){
                System.out.println("此书已存在");
                return;
            }
        }
        System.out.println("请输入作者");
        String author = in.nextLine();
        System.out.println("请输入书的类型");
        String type = in.nextLine();
        System.out.println("请输入价格");
        int price = in.nextInt();
        Book book = new Book(name,author,price,type);

        bookList.setBooks(bookList.getBookCount(), book);

        bookList.setBookCount(bookList.getBookCount() + 1);

        System.out.println("增加成功");
    }

}
